package com.liu.lab03.Servlet;

import com.liu.lab03.dao.MusicDao;
import com.liu.lab03.pojo.Music;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

// 刘小文  -2420710103---
@WebServlet(name = "showAllMusicServlet", value = "/showAllMusics")
public class showAllMusicServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 调用 dao 方法
        MusicDao dao = new MusicDao();
        // 把返回来的数据存入 allMusics 中
        List<Music> allMusics = dao.findAllMusics();

        //设置session
        HttpSession session = request.getSession();
        session.setAttribute("allMusics", allMusics);
        // 并且响应到我们的 Music.jsp 页面中去 携带我们参数
        response.sendRedirect("Music.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
    }
}
